package com.elontian;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.elontian.callBack.LoadImgCallBack;
import com.elontian.client.CacheImageClient;
import com.elontian.client.HttpRequestClient;
import com.elontian.http.R;
import com.elontian.http.async2.handler.AsyncHttpHandler;
import com.elontian.http.async2.modle.Response;
import com.elontian.http.async2.util.HttpParams;

public class Eloingtian_http_asyncActivity extends Activity {
	/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		final ImageView img = (ImageView) this.findViewById(R.id.img);

		final TextView text = (TextView) this.findViewById(R.id.text);

		String url = "http://www.2cto.com/uploadfile/2013/0327/20130327113808166.jpg";

		// HttpRequestClient.AsyncLoadImg(url, img, 100, 100,
		// new AsyncHttpHandler() {
		//
		// @Override
		// public void succ(Response obj) {
		// // TODO Auto-generated method stub
		// String url = (String) obj.get(HttpParams.URL);
		// ImageView view = (ImageView) obj
		// .get(HttpParams.IMAGEVIEW);
		// Bitmap reslut = (Bitmap) obj.get(HttpParams.RESULT);
		//
		// view.setImageBitmap(reslut);
		//
		// }
		//
		// @Override
		// public void fail(Exception e) {
		// // TODO Auto-generated method stub
		//
		// }
		// });

		CacheImageClient.loadImg(url, img, 100, 100, new LoadImgCallBack() {

			@Override
			public void succ(String url, ImageView view, Object result) {
				// TODO Auto-generated method stub

				view.setImageBitmap((Bitmap) result);
			}

			@Override
			public void fail(Object result) {
				// TODO Auto-generated method stub
			}
		});

		url = "http://app.sigm.com.cn/index.php?com=com_appService&method=save&app_com=com_pro&content_type=img&children=all&data=1&app_method=lists&data=1&app_optionid=929&row=10&page=1";

		HttpRequestClient.AsyncGet(url, new AsyncHttpHandler() {

			@Override
			public void succ(Response obj) {
				// TODO Auto-generated method stub
				Log.d("get", obj + "");
				String reslult = (String) obj.get(HttpParams.RESULT);
				text.setText(reslult);
			}

			@Override
			public void fail(Exception e) {
				// TODO Auto-generated method stub

			}
		});

		// CodeBoyAsyncHttp.getSync(url, XStreamDecorator.NET, new
		// HttpCallBack() {
		//
		// @Override
		// public void succ(String url, Object result) {
		// // TODO Auto-generated method stub
		// text.setText(result.toString());
		// }
		//
		// @Override
		// public void fail(Exception e) {
		// // TODO Auto-generated method stub
		//
		// }
		// });

	}
}